package bb.lanxing.util.ui;

import android.app.Dialog;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.google.android.material.bottomsheet.BottomSheetBehavior;
import com.google.android.material.bottomsheet.BottomSheetDialogFragment;

import java.io.Serializable;
import java.util.List;

import bb.lanxing.R;
import bb.lanxing.databinding.FragmentBottomSheetChoiceBinding;
import bb.lanxing.databinding.LayoutChooseDialogTipsItemBinding;
import kotlin.collections.CollectionsKt;
import kotlin.jvm.internal.DefaultConstructorMarker;
import kotlin.jvm.internal.Intrinsics;

public class ChoiceBottomSheetFragment extends BottomSheetDialogFragment {
    public static final Companion Companion = new Companion(null);
    private FragmentBottomSheetChoiceBinding binding;
    private ChoiceBean choiceBean;
    private BottomSheetBehavior<?> mBottomSheetBehavior;

    public interface ChoiceBottomSheetFragmentActionHandler {
        void onNegativeBtnClick(BottomSheetDialogFragment bottomSheetDialogFragment);

        void onPositiveBtnClick(BottomSheetDialogFragment bottomSheetDialogFragment);
    }

    public static final ChoiceBottomSheetFragment newInstance(ChoiceBean choiceBean) {
        return Companion.newInstance(choiceBean);
    }

    @Override
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        Bundle arguments = getArguments();
        if (arguments != null) {
            this.choiceBean = (ChoiceBean) arguments.getSerializable("choiceBean");//ARG_PARAM_CHOICE_BEANKt.ARG_PARAM_CHOICE_BEAN
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup viewGroup, Bundle bundle) {
        List<Integer> tips;
        int i = 0;
        FragmentBottomSheetChoiceBinding inflate = FragmentBottomSheetChoiceBinding.inflate(inflater, viewGroup, false);
        this.binding = inflate;
        inflate.title.setText(choiceBean.title);
        inflate.allow.setText(choiceBean.positiveBt);
        inflate.denied.setText(choiceBean.negativeBt);
        ChoiceBean choiceBean = this.choiceBean;
        if ((choiceBean != null ? choiceBean.getTips() : null) == null) {
            binding.llTips.setVisibility(View.GONE);
        } else {
            ChoiceBean choiceBean2 = this.choiceBean;
            if ((tips = choiceBean2.getTips()) != null) {
                for (Number obj : tips) {
                    int i2 = i + 1;
                    int intValue = obj.intValue();
                    if (intValue > 0) {
                        LayoutChooseDialogTipsItemBinding inflate2 = LayoutChooseDialogTipsItemBinding.inflate(getLayoutInflater());
                        inflate2.tvIndex.setText(String.valueOf(i2));
                        inflate2.tvContent.setText(getString(intValue));
                        binding.llTips.addView(inflate2.getRoot());
                    }
                    i = i2;
                }
            }
        }
        binding.allow.setOnClickListener(view -> choiceBean.handler.onPositiveBtnClick(ChoiceBottomSheetFragment.this));
        binding.denied.setOnClickListener(view -> choiceBean.handler.onNegativeBtnClick(ChoiceBottomSheetFragment.this));
        return binding.getRoot();
    }

    @Override
    public void onStart() {
        super.onStart();
        try {
            Dialog dialog = getDialog();
            assert dialog != null;
//            Window window = dialog.getWindow();
//            View findViewById = window.findViewById(R.id.design_bottom_sheet);
//            findViewById.setBackgroundDrawable(new ColorDrawable(0));
//            BottomSheetBehavior from = BottomSheetBehavior.from(findViewById);
//            if (from == null) {
//                return;
//            }
//            from.setState(BottomSheetBehavior.STATE_EXPANDED);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static final class Companion {
        public Companion(DefaultConstructorMarker defaultConstructorMarker) {
            this();
        }

        private Companion() {
        }

        public final ChoiceBottomSheetFragment newInstance(ChoiceBean choiceBean) {
            ChoiceBottomSheetFragment choiceBottomSheetFragment = new ChoiceBottomSheetFragment();
            Bundle bundle = new Bundle();
            bundle.putSerializable("choiceBean", choiceBean);//ARG_PARAM_CHOICE_BEANKt.ARG_PARAM_CHOICE_BEAN
            choiceBottomSheetFragment.setArguments(bundle);
            return choiceBottomSheetFragment;
        }
    }

    public static final class ChoiceBean implements Serializable {
        private ChoiceBottomSheetFragmentActionHandler handler;
        private int icon;
        private int des = R.string.st_empty_string;
        private List<Integer> tips = CollectionsKt.emptyList();
        private String desString = "";
        private String desStringBottom = "";
        private int pageTitle = R.string.st_empty_string;
        private int title = R.string.st_empty_string;
        private int positiveBt = R.string.st_empty_string;
        private int negativeBt = R.string.st_empty_string;

        public final boolean visibility(int i) {
            return i != R.string.st_empty_string;
        }

        public final boolean visibilityDrawable(int i) {
            return i != 0;
        }

        public final int getDes() {
            return this.des;
        }

        public final void setDes(int i) {
            this.des = i;
        }

        public final List<Integer> getTips() {
            return this.tips;
        }

        public final void setTips(List<Integer> list) {
            Intrinsics.checkNotNullParameter(list, "<set-?>");
            this.tips = list;
        }

        public final String getDesString() {
            return this.desString;
        }

        public final void setDesString(String str) {
            Intrinsics.checkNotNullParameter(str, "<set-?>");
            this.desString = str;
        }

        public final String getDesStringBottom() {
            return this.desStringBottom;
        }

        public final void setDesStringBottom(String str) {
            Intrinsics.checkNotNullParameter(str, "<set-?>");
            this.desStringBottom = str;
        }

        public final int getIcon() {
            return this.icon;
        }

        public final void setIcon(int i) {
            this.icon = i;
        }

        public final int getPageTitle() {
            return this.pageTitle;
        }

        public final void setPageTitle(int i) {
            this.pageTitle = i;
        }

        public final int getTitle() {
            return this.title;
        }

        public final void setTitle(int i) {
            this.title = i;
        }

        public final int getPositiveBt() {
            return this.positiveBt;
        }

        public final void setPositiveBt(int i) {
            this.positiveBt = i;
        }

        public final int getNegativeBt() {
            return this.negativeBt;
        }

        public final void setNegativeBt(int i) {
            this.negativeBt = i;
        }

        public final ChoiceBottomSheetFragmentActionHandler getHandler() {
            return this.handler;
        }

        public final void setHandler(ChoiceBottomSheetFragmentActionHandler choiceBottomSheetFragmentActionHandler) {
            this.handler = choiceBottomSheetFragmentActionHandler;
        }
    }
}
